<template lang="pug">
  .user
    Dropdown(@on-click='handleChangeItem',placement="bottom-end")
      aside
        span.user-avatar
          img(src='../../../assets/images/avatar.png')
        span.user-name {{username}}
      DropdownMenu(slot='list')
        DropdownItem 退出
</template>

<script>
import createAPI from '@/plugins/axios'

export default {
  data() {
    return {
      username: sessionStorage.getItem('username')
    }
  },
  methods: {
    handleChangeItem: async function() {
      try {
        await createAPI('sign/signOut', 'post', { data: { userId: sessionStorage.getItem('userId') } })
        this.$cookie.remove('token')
        sessionStorage.clear()
        location.reload()
      } catch (error) {}
    }
  }
}
</script>

